<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
                <div class="layui-form layui-form-pane">
                    <div class="layui-tab layui-tab-brief" lay-filter="user">
                        <ul class="layui-tab-title">
                            <li class="layui-this">
                                发表新帖
                            </li>
                        </ul>
                        <br>
                        <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">
                                                所在类别
                                            </label>
                                            <div class="layui-input-block">
                                    <select lay-verify="required" name="cid">
                                    <option></option>
                                    <?php foreach ($category as $v) { ?>

                                      <optgroup label="<?php echo $v['cname'] ?>"> 
                                         <?php foreach ($v['son'] as  $value) { ?>
                                             <option value="<?php echo  $value['id'] ?>"><?php echo $value['cname'] ?></option>
                                         <?php } ?>   
                                        </optgroup>
                                            <?php  } ?>
                                      </select>

                                          </div>
                                        </div>
                        <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                            <div class="layui-tab-item layui-show">
                                <form action="" method="post">
                                  <div class="layui-form-item">
                                        <label for="L_title" class="layui-form-label">
                                            标题
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="text" id="L_title" name="title" required lay-verify="required"
                                            autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-form-text">
                                       <div class="layui-input-block"><textarea id="L_content" name="content"placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
                                      </div>
                                        <label for="L_content" class="layui-form-label" style="top: -2px;">
                                            描述
                                        </label>
                                    </div>
                                                         
                                    </div>
                                    <div class="layui-form-item">
                                        <button class="layui-btn" lay-filter="add" lay-submit>
                                            立即发布
                                        </button>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
        <script src="__PUBLIC__/admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="__PUBLIC__/admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer','layedit'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer
              ,layedit = layui.layedit;


                layedit.set({
                  uploadImage: {
                    url: "./upimg.json" //接口url
                    ,type: 'post' //默认post
                  }
                })
  
            //创建一个编辑器
            index = layedit.build('L_content',{
                  height: 180
             });
            
              

              //监听提交
              form.on('submit(add)', function(data){
                console.log(data);
                content=layedit.getContent(index);
                 if (content.length<10) {
                   layer.msg('问题内容少于10，请重新输入',function(){});
                   return false;
                  };   
                data.field.content = content;
                 $.ajax({
                     url: '{:U('admin/question/question_checkadd')}',
                     type: 'post',
                     dataType: 'json',
                     data: data.field,
                 })
                 .done(function(respones) {
                  console.log("success");
                    if (respones.error==1) {
                      layer.alert(respones.info, {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                      });
                    }else{
                    layer.alert(respones.info, {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                      });
                    };
                 })
                 .fail(function() {
                    alert(777);
                     console.log("error");
                 })
                return false;
              });
            });
        </script>
        <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
    </body>

</html>